/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pclong.fightlandlordserver.service;

import com.pclong.fightlandlordserver.ConfigService;
import com.pclong.fightlandlordserver.TankAgentConfigEntity;
import com.pclong.fightlandlordserver.UserConfigEntity;
import com.pclong.fightlandlordserver.util.Crypto;
import com.pclong.fightlandlordserver.util.EncryptionUtil;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;

/**
 * 提供各种数据操作
 *2011-09-13
 * @author long@7road.com
 */
//@Service
public class DataService {

    static {
    }

    public DataService() {
    }

    public static UserConfigEntity GetUserByUserName(String userName) {
        UserConfigEntity user = null;
        for (Iterator it = ConfigService.getTankAgentConfig().getUsers().iterator(); it.hasNext();) {
            user = (UserConfigEntity) it.next();
            if (user.getUserName().equals(userName)) {
                return user;
            }
        }
        return null;
    }

    public static UserConfigEntity Login(String username, String password){
        UserConfigEntity user = DataService.GetUserByUserName(username);
        try {
             String entrypassword=Crypto.SHA1(password);
        if (user == null || (entrypassword== null ? user.getPassword() != null : !entrypassword.equals(user.getPassword()))) {
            // 用户名或密码错误            
            return null;
        }
        } catch (NoSuchAlgorithmException ex1) {
              return null;
        }
         catch (UnsupportedEncodingException ex1) {
               return null;
        }
         catch (Exception ex3) {
               return null;
        }
       
        return user;
    }
}
